import {request} from "../../api/request";

const submit = (news, from) => {
    request({
        url: '/news/predict',
        method: 'POST', // 或者 'POST'、'PUT' 等，根据接口要求确定
        from: from,
        data: news,
        // 要传递的参数对象，如果是 GET 请求可以放在 url 中作为查询参数
        header: {
            // 设置请求头，例如可以设置 Content-Type、Authorization 等
            'Content-Type': 'application/json'
        }
    }).then(response => {
        const res = response.data
        const code = res.code
        if (code === 0 && res.data) {
            const data = res.data
            const newsId = data.news.id
            delete data.news
            news = {
                ...news,
                newsId,
                result: data
            }
            wx.navigateTo({
                url: `/pages/result/result?news=${encodeURIComponent(JSON.stringify(news))}`
            });
        }
    }).catch(err => {
        console.log(err)
    })
}

export {submit}